﻿$(function() {
	//三个图标切换-开始
	var $lia = $("#le-c").find("li")
	$lia.click(function() {
			for(var i = 0; i < $lia.length; i++) {
				$lia[i].innerHTML = "<img src='img/" + (i + 1) + "-2.png'>";
			}
			var h = $(this)[0].children[0].src
			$(this)[0].children[0].src = h.substring(0, h.length - 5) + '1.png';
			if($(this).attr("nu") == 1) {
				$("#le-ul1").css("display", "block");
				$("#le-ul1").find("ul").css("margin-top","0px")
				$("#le-ulb").css("display", "none");
			} else if($(this).attr("nu") == 2) {
				$("#le-ul1").css("display", "none");
				$("#le-ulb").css("display", "block");
				$("#le-ulb").find("ul").css("margin-top","0px")
			}
			$(".gdt").find("span").css("top","0px")
		})
		//左侧聊天信息初始化-开始
	var xinxi = haoyou.xinxi;
	var $ula = $("#le-ul1").find("ul");
	for(var k = 0; k < xinxi.length; k++) {
		var $li = $("<li><div class='mintx'><img src='" + xinxi[k].img + "' /></div><div class='min'><p><mz>" + xinxi[k].name + "</mz><label class='min-a'>" + xinxi[k].shijian + "</label></p><p><span>" + xinxi[k].liaotian + "</span></p></div></li>")
		$ula.append($li);
		if(k == 0) {
			$li.css("background-color", "#505050");
			$li.find("mz").css("color", "#CBCBCB");
			$li.find(".min-a").css("color", "#CBCBCB")
		}
	}
	//左侧聊天信息初始化-结束
	//左侧好友信息初始化-开始
	var $ulb = $("#le-ulb").find("ul")
	for(var k = 0; k < xinxi.length; k++) {
		var $lib = $("<li class='le-lib'><div class='le-ulb-b'><div class='le-ulb-b1'><img src='" + xinxi[k].img + "'/></div><div class='le-ulb-b2'>" + xinxi[k].name + "</div></div></li>")
		$ulb.append($lib);
	}
	$("#le-ulb").css("display", "none")
		//左侧好友信息初始化-结束
		//好友信息li点击-开始
	$(".le-lib").click(function() {
			$("#ria-a").html($(this).find(".le-ulb-b2").html());
			for(var i = 0; i < xinxi.length; i++) {
				if($(this).find(".le-ulb-b2").html() == xinxi[i].name) {
					$("#ria-b1").html(xinxi[i].hua);
					txsrc = $(this).find("img")[0].src;
					break;
				}
			}
		})
		//好友信息li点击-结束
		//左侧滚动条-开始
	var $ul;
	$("#le-d").mouseover(function(event) {
		if($("#le-ul1").css("display") == "block") {
			var ulh = $("#le-ul1").css("height");
			$ul = $("#le-ul1 ul");
		} else if($("#le-ulb").css("display") == "block") {
			var ulh = $("#le-ulb").css("height");
			$ul = $("#le-ulb ul");
		}
		if(parseInt(ulh) > 445) {
			$(this).find(".gdt").show()
		}
	}).mouseout(function(event) {
		$(this).find(".gdt").hide()
	})
	var stop = 0;
	var anxia = false;
	var mousetop = 0;
	var ultop = 0;
	$(".gdt span").mousedown(function(event) {
		stop = parseInt($(this).css("top"));
		anxia = true;
		mousetop = event.clientY;
		ultop = parseInt($ul.css("margin-top"))
	})
	$("#le-d").mouseup(function(event) {
			anxia = false;
		}).mousemove(function(event) {
			var $span = $(this).find(".gdt span")
			var moveh = event.clientY - mousetop
			var t = moveh + stop
			if(anxia && t >= 0 && t <= 300) {
				$span.css("top", t + "px")
				var ulh = parseInt($ul.css("height")) - 445;
				var addh = moveh / 300 * ulh * -1;
				$ul.css("margin-top", (ultop + addh) + "px")
			}
		})
		//左侧滚动条-结束
		//右侧滚动条-开始
		/*$("#ria-b").mouseover(function() {
			if(parseInt($("#ria-b1").css("height")) > 422) {
				$(this).find(".gdtb").show()
			}
		}).mouseout(function() {
			$(this).find(".gdtb").hide()
		})
		var stop2 = 0;
		var anxia2 = false;
		var mousetop2 = 0;
		var ultop2 = 0;
		$(".gdtb span").mousedown(function() {
			stop2 = parseInt($(this).css("top"));
			anxia2 = true;
			mousetop2 = event.clientY;
			ultop2 = parseInt($("#ria-b1").css("margin-top"))
		})
		$("#ria-b").mouseup(function() {
				anxia2 = false;
			}).mousemove(function() {
				var $span = $(this).find(".gdtb span")
				var moveh = event.clientY - mousetop2
				var t = moveh + stop2
				if(anxia2 && t >= 0 && t <= 300) {
					$span.css("top", t + "px")
					var ulh = parseInt($("#ria-b1").css("height")) - 422;
					var addh = moveh / 300 * ulh * -1;
					$("#ria-b1").css("margin-top", (ultop2 + addh) + "px")
				}
			})*/
		//右侧滚动条-结束
		//左侧聊天li点击-开始
	var txsrc = "img/tx-1.jpg" //头像要改变的路径
	$("#le-d").find("li").click(function() {
			$("#ria-a").html($(this).find("mz").html());
			for(var i = 0; i < xinxi.length; i++) {
				if($(this).find("mz").html() == xinxi[i].name) {
					$("#ria-b1").html(xinxi[i].hua);
					txsrc = $(this).find("img")[0].src;
					break;
				}
			}
			var $linum = $("#le-d").find("li")
			for(var k = 0; k < $linum.length; k++) {
				$linum.css("background-color", "#2E3238")
				$linum.find("mz").css("color", "#848586");
				$linum.find(".min-a").css("color", "#848586");
			}
			$(this).css("background-color", "#505050");
			$(this).find("mz").css("color", "#CBCBCB");
			$(this).find(".min-a").css("color", "#CBCBCB");
		})
		//左侧聊天li点击-结束
		//发送-开始
	$("#spen").click(function() {
			var liaotian;
			if($("#ria-c1").html().trim() != "") {
				var newmz = $("#ria-a").html()
				var x = Math.random();
				var spent = $("#ria-c1").html();
				var time = new Date;
				var hh = time.getHours() >= 10 ? time.getHours() : "0" + time.getHours();
				var ff = time.getMinutes() >= 10 ? time.getMinutes() : "0" + time.getMinutes();
				var ntime = hh + "：" + ff;
				var $ndiv1 = $("<div class='ria-b11'><div class='time'>" + ntime + "</div><div class='right'><div class='right-tx'><img src='img/tx4.jpg' /></div><div class='right-in'>" + spent + "</div></div><div class='clear'></div></div>");
				$("#ria-b1").append($ndiv1);
				$.post("http://www.tuling123.com/openapi/api", {
					key: "9ab3d66cd4774b67974ada073e2bd3c2",
					info: spent,
					userid: "123456"
				}, function(data) {
					liaotian = data.text;
					var $ul1li = $("#le-ul1").find("li");
					for(var k = 0; k < $ul1li.length; k++) {
						if($ul1li[k].children[1].children[0].children[0].innerHTML == newmz.trim()) {
							$ul1li[k].children[1].children[1].children[0].innerHTML = liaotian;
							$ul1li[k].children[1].children[0].children[1].innerHTML = ntime;
						}
					}
					if(data.url) {
						liaotian += "<a class='a-class-1' href='" + data.url + "'>点击前往<a />"
					}
					if(data.list) {
						liaotian = "<div class='xinwen'><div class='xinwen-1'><img src='" + data.list[0].icon + "'/><p class='xinwen-1-pa'></p><p class='xinwen-1-pb'>" + data.list[0].article + "<p/></div><div class='xinwen-2'><p>" + data.list[1].article + "</p><img src='" + data.list[1].icon + "'/></div><div class='xinwen-2'><p>" + data.list[2].article + "</p><img src='" + data.list[2].icon + "'/></div></div>"
					}
					var $ndiv2 = $("<div class='ria-b11'><div class='time'>" + ntime + "</div><div class='left'><div class='left-tx'><img src='" + txsrc + "' /></div><div class='left-in'>" + liaotian + "</div></div><div class='clear'></div></div>");
					$("#ria-b1").append($ndiv2);
					for(var i = 0; i < xinxi.length; i++) {
						if(xinxi[i].name == newmz.trim()) {
							xinxi[i].hua = $("#ria-b1").html();
							break;
						}
					}
					$("#ria-b1")[0].scrollTop = $("#ria-b1")[0].scrollHeight;
				})

			}
			$("#qq").css("display", "none");
			$("#ria-b1")[0].scrollTop = $("#ria-b1")[0].scrollHeight;
		})
		//发送-结束
		//表情弹出-开始
	$("#ma-ri-fa").click(function() {
		var $qq = $("#qq")
		if($qq.css("display") == "none") {
			$qq.css("display", "block")
		} else {
			$qq.css("display", "none")
		}
	})
	$("#qq").find("td").click(function() {
			var $tex = $("#ria-c1");
			$tex.append($(this).html())
		})
		//表情弹出-结束
		//表情切换-开始
	$(".qq-tab-ul").find("li").click(function() {
			$(".qq-tab-ul").find("li").removeClass("qq-tab-dj");
			$(this).addClass("qq-tab-dj");
		})
		//表情切换-结束
})